/**
 * “权限管理”相关接口
 */
import Http from 'utils/request'

const context = process.env.VUE_APP_CONSOLE_PATH

export default {
  /**
   * 添加权限
   * @param params
   */
  addPerm: params =>
    Http.fetch(context + '/sys_perm', params, {
      method: 'post'
    }),

  /**
   * 同步菜单权限数据
   * @param data
   */
  syncMenuPerms: params =>
    Http.fetch(context + '/sys_perm/sync/menu', params, {
      method: 'post'
    }),

  /**
   * 同步接口权限数据
   * @param data
   */
  syncApiPerms: params =>
    Http.fetch(context + '/sys_perm/sync/api', params, {
      method: 'post'
    }),

  /**
   * 删除权限
   * @param data
   */
  deletePerm: params =>
    Http.fetch(context + '/sys_perm', params, {
      method: 'delete'
    }),

  /**
   * 更新权限
   * @param data
   */
  updatePerm: params =>
    Http.fetch(context + '/sys_perm/info', params, {
      method: 'patch'
    }),

  /**
   * 查询接口权限元数据
   * @param perm
   */
  listApiPermMetadata: params =>
    Http.fetch(context + '/sys_perm/meta/api', params, {
      method: 'get'
    }),

  /**
   * 列出所有菜单、按钮、接口等权限
   * @param perm
   */
  listAllPermissions: params =>
    Http.fetch(context + '/sys_perm/list/all', params, {
      method: 'get'
    }),

  /**
   * 列出按钮权限，按parent字段分组
   * @param perm
   */
  listBtnPermGroupByParent: params =>
    Http.fetch(context + '/sys_perm/list/btn_perm_map', params, {
      method: 'get'
    })
}
